var strValue=[];
var oldyear;
var id =$("#wetlandParkId").val();
$('[data-tab]').on('show.zui.tab', function(e) {
	if(e.target.hash=='#basicInfo'){
		var btn=document.getElementsByTagName('button');
		var boolean=true;
		for(var i=0;i<btn.length;i++){
			if(btn[i].className=='btn btn-primary btn-success'){
				console.log(btn[i].disabled);
				if(btn[i].disabled==false){
					boolean=false;
				}
			}
		}
		console.log(boolean);
		if(boolean==false){
			 new $.zui.Messager('如果您有修改，请先保存。', {
			        icon: 'bell', // 定义消息图标
			        	type:'danger' 
			    }).show();
			 e.preventDefault();
		}else{
			if(strValue.wlin_location_gis_layer==null){
				
			}else{
				$('#location_gis_layer').find('option[value="'+strValue.wlin_location_gis_layer+'"]').attr('selected',true);
			}
			if(strValue != null){
				$("#location_gis_mapserver").empty();
				$("#location_gis_mapserver").append("<option selected='selected' value=" + strValue.wlin_gis_mapserver + ">"
						+ strValue.wlin_gis_mapserver + "</option>");
			}	
		}			
	}else if(e.target.hash=='#protectionMainBody'){				
		if(strValue.wlin_sectorization_layer==null){
			
		}else{
			$("#sectorization_layer").find('option[value="'+strValue.wlin_sectorization_layer+'"]').attr('selected',true);
		}
		if (strValue != null) {
			
			$("#sectorization_layer").find("option[value='"+strValue.wlin_sectorization_layer+"']").attr("selected",true);
			var stardate = new Date(strValue.wlin_bulid_date);
			var month=stardate.getMonth()+1;
			$("#build_date").attr("value", stardate.getFullYear()+"-"+month+"-"+stardate.getDate());
		}
	}else if(e.target.hash=='#wetlandType'){
		if(strValue.wlin_type_gis_layer==null){
			
		}else{
			$("#type_gis_layer").find('option[value="'+strValue.wlin_type_gis_layer+'"]').attr('selected',true);
		}
		if (strValue != null) {
			
			$("#type_gis_layer").find("option[value='"+strValue.wlin_type_gis_layer+"']").attr("selected",true);
			var typeinfos = strValue.wlin_type_infos;
			var arrArea = $("input[name='wetlandTypeArea']");
			var arrScale = $("input[name='wetlandTypeScale']");
			if(typeinfos!=null){
				if(typeinfos.length==0){
					
				}else{
					for(var i=0;i<arrArea.length;i++){
						$(arrArea[i]).val(typeinfos[i].area);
						
						$(arrScale[i]).val(typeinfos[i].proportion);
					}
				}
			}
	
		}

	}else if(e.target.hash=='#naturaFeature'){
		if (strValue != null) {
								if(strValue.wlin_landform_types.length>=1){
									var wlt = $("input[name='wetlandLandformTypes']");
									for(var i=0;i<strValue.wlin_landform_types.length;i++){
										for(var j=0;j<wlt.length;j++){
											if($(wlt[j]).val()==strValue.wlin_landform_types[i]){
												//alert(strValue.wlin_landform_types[i]);
												$(wlt[j]).attr("checked",true);
											}
										}
									}
								}
								
								if(strValue.wlin_soil_types.length>=1){
									var arr = $("input[name='wetlandSoilTypes']");
									for(var i=0;i<strValue.wlin_soil_types.length;i++){
										for(var j=0;j<arr.length;j++){
											if($(arr[j]).val()==strValue.wlin_soil_types[i]){
												$(arr[j]).attr("checked",true);
											}
										}
									}
								}
								
								var protection = strValue.wlin_peat_type;
								if(protection!=null){
									var protectionlevel = $("input[name='wetlandPeatTypes']");
									for(var i=0;i<protectionlevel.length;i++){
											                        var checkValue=$(protectionlevel[i]).val();
											                        if(protection==checkValue){
											                        	$(protectionlevel[i]).attr("checked",true);
											                        }
											                  
									 }
								}
								
								if(strValue.wlin_river_basin.length>=1){
									var arr = $("input[name='wetlandRevierBasins']");
									for(var i=0;i<strValue.wlin_river_basin.length;i++){
										for(var j=0;j<arr.length;j++){
											if($(arr[j]).val()==strValue.wlin_river_basin[i]){
												$(arr[j]).attr("checked",true);
											}
										}
									}
								}
								
								
								var wws = strValue.wlin_water_situation;
								if(wws.length>0){
									var checkArray =wws;
									var checkBoxAll = $("input[name='wetlandWaterSituations']");
									for(var i=0;i<checkArray.length;i++){
									                     //获取所有复选框对象的value属性，然后，用checkArray[i]和他们匹配，如果有，则说明他应被选中
										$.each(checkBoxAll,function(){
											                        //获取复选框的value属性
											                        var checkValue=$(this).val();
											                        if(checkArray[i]==checkValue){
											                             $(this).attr("checked",true);
											                        }
											                    })
									 }
								}
								
								var wwr = strValue.wlin_water_recharge;
								if(wwr.length>0){
									var checkArray =wwr;
									var checkBoxAll = $("input[name='wetlandWaterRecharges']");
									for(var i=0;i<checkArray.length;i++){
									                     //获取所有复选框对象的value属性，然后，用checkArray[i]和他们匹配，如果有，则说明他应被选中
										$.each(checkBoxAll,function(){
											                        //获取复选框的value属性
											                        var checkValue=$(this).val();
											                        if(checkArray[i]==checkValue){
											                             $(this).attr("checked",true);
											                        }
											                    })
									 }
								}
								
								var wwd = strValue.wlin_water_direction;
								if(wwd.length>0){
									var checkArray =wwd;
									var checkBoxAll = $("input[name='wetlandWaterDirections']");
									for(var i=0;i<checkArray.length;i++){
									                     //获取所有复选框对象的value属性，然后，用checkArray[i]和他们匹配，如果有，则说明他应被选中
										$.each(checkBoxAll,function(){
											                        //获取复选框的value属性
											                        var checkValue=$(this).val();
											                        if(checkArray[i]==checkValue){
											                             $(this).attr("checked",true);
											                        }
											                    })
									 }
								}
								
								var wwst = strValue.wlin_water_stability;
								if(wwst.length>0){
									var checkArray =wwst;
									var checkBoxAll = $("input[name='wetlandWaterStabilitys']");
									for(var i=0;i<checkArray.length;i++){
									                     //获取所有复选框对象的value属性，然后，用checkArray[i]和他们匹配，如果有，则说明他应被选中
										$.each(checkBoxAll,function(){
											                        //获取复选框的value属性
											                        var checkValue=$(this).val();
											                        if(checkArray[i]==checkValue){
											                             $(this).attr("checked",true);
											                        }
											                    })
									 }
								}
								
								var ws = strValue.wlin_sediment;
								if(ws.length>0){
									var checkArray =ws;
									var checkBoxAll = $("input[name='wetlandSediments']");
									for(var i=0;i<checkArray.length;i++){
									                     //获取所有复选框对象的value属性，然后，用checkArray[i]和他们匹配，如果有，则说明他应被选中
										$.each(checkBoxAll,function(){
											                        //获取复选框的value属性
											                        var checkValue=$(this).val();
											                        if(checkArray[i]==checkValue){
											                             $(this).attr("checked",true);
											                        }
											                    })
									 }
								}
								
								if(strValue.wlin_climatic_region.length>=1){
									
									for(var i=1;i<strValue.wlin_climatic_region.length;i++){
										naturaFeature_add_climate();
										
									}
									var arr = $("input[name='wlin_climatic_region']");
									for(var i=1;i<strValue.wlin_climatic_region.length;i++){
										$(arr[i]).val(strValue.wlin_climatic_region[i]);
									}
									
								}
								
								
							}


			}else if(e.target.hash=='#ecologicalFun'){
						if (strValue != null) {
							var provide = strValue.wlin_provide_service;
							var provideCode = $("select[name='provideSense']");	
							if(provide.length!=0){
								for(var i = 0;i<provideCode.length;i++){
									$(provideCode[i]).find("option[value='"+provide[i].sense+"']").attr("selected",true);
								}
							}

							 
							var adjust = strValue.wlin_adjust_service;
							var adjustCode = $("select[name='adjustSense']");	
							if(adjust.length!=0){
								for(var i = 0;i<adjustCode.length;i++){
									$(adjustCode[i]).find("option[value='"+adjust[i].sense+"']").attr("selected",true);
								}
							}

							
							var culture = strValue.wlin_culture_service;
							var cultureCode = $("select[name='cultureSense']");	
							if(culture.length!=0){
								for(var i = 0;i<cultureCode.length;i++){
									$(cultureCode[i]).find("option[value='"+culture[i].sense+"']").attr("selected",true);
								}
							}
						
							
							var support = strValue.wlin_support_service;
							var supportCode = $("select[name='supportSense']");	
							if(support.length!=0){
								for(var i = 0;i<supportCode.length;i++){
									$(supportCode[i]).find("option[value='"+support[i].sense+"']").attr("selected",true);
								}
							}

							
						}
			}else if(e.target.hash=='#managementOrganization'){
								if (strValue != null) {
								
									$('#management_name').val(strValue.wlin_management_name);
									$('#management_address').val(strValue.wlin_management_address);
									if(strValue.wlin_principal!=null){
										$('#principal_name').val(strValue.wlin_principal.name);
										$('#principal_title').val(strValue.wlin_principal.title);
										$('#principal_telephone').val(strValue.wlin_principal.telephone);
										$('#principal_email').val(strValue.wlin_principal.email);
									}
									if(strValue.wlin_linkman!=null){
										$('#linkman_name').val(strValue.wlin_linkman.name);
										$('#linkman_telephone').val(strValue.wlin_linkman.telephone);
										$('#linkman_email').val(strValue.wlin_linkman.email);
									}
								

									$('#competent_department').val(strValue.wlin_competent_department);

									
								}

			}else if(e.target.hash=='#landOwnership'){
								if (strValue != null) {
									$('#landproperty').val(strValue.wlin_landproperty);
									$('#landusage').val(strValue.wlin_landusage);	
								}


			}else if(e.target.hash=='#threatenedStatus'){
							if (strValue != null) {
								//alert(strValue.length);
								var arr = $("input[name='threatenedContent']");
								
								for ( var i=0;i<arr.length;i++) {
									//console.log(arr[i]);
									$(arr[i]).val(strValue[i]);
								}
							}
			}else if(e.target.hash=='#socioEconomic'){
				if(strValue.wlin_soil_gis_layer==null){
					
				}else{
					$("#soil_gis_layer").find('option[value="'+strValue.wlin_soil_gis_layer+'"]').attr('selected',true);
				}
				if (strValue != null) {
						$("#soil_gis_mapserver").empty();
						$("#soil_gis_mapserver").append("<option selected='selected' value=" + strValue.wlin_gis_mapserver + ">"
												+ strValue.wlin_gis_mapserver + "</option>");
						$("#soil_gis_layer").find("option[value='"+strValue.wlin_soil_gis_layer+"']").attr("selected",true);
						var arr = $("input[name='content']");
						if(strValue.wlin_social_econommic_indicator.length!=0){
							for ( var i=0;i<5;i++) {
								
								$(arr[i]).val(strValue.wlin_social_econommic_indicator[i].content);
							}
						}

						if(strValue.wlin_social_econommic_indicator.length==6){
							if(strValue.wlin_social_econommic_indicator[5].content!=null){
								
								var protectionlevel = $("input[name='content']");
								for(var i=5;i<protectionlevel.length;i++){
								                     //获取所有复选框对象的value属性，然后，用checkArray[i]和他们匹配，如果有，则说明他应被选中
									
										                        //获取复选框的value属性
										                        var checkValue=$(protectionlevel[i]).val();
										                        if(strValue.wlin_social_econommic_indicator[5].content==checkValue){
										                        	$(protectionlevel[i]).attr("checked",true);
										                        }
										                  
								 }
							}
						}	
					}

			}else if(e.target.hash=='#multiMedia'){
			
				
				$('#showimage').empty();
				$('#showvideo').empty();
				$('#showaudio').empty();
				if(strValue.wlin_picture.length==0){
					
				}else{
					for(var i=0;i<strValue.wlin_picture.length;i++){
						
						var id=strValue.wlin_picture[i].split('/')[3];
						$('#showimage').append("<div class='col-sm-3' id="+id+">"
								+"<img data-toggle='lightbox' src="+strValue.wlin_picture[i]+" data-image="+strValue.wlin_picture[i]+"  class='img-thumbnail' alt='' width='200'>"
								+"<button type='button' class='btn btn-danger' onclick='delimg(this)' style='display:none'><i class='icon icon-trash bigger-130'></i> 删除</button></div>");
					}
				}

				if(strValue.wlin_voice.length==0){
					
				}else{
					for(var i=0;i<strValue.wlin_voice.length;i++){
						
						var id=strValue.wlin_voice[i].split('/')[3];
						$('#showaudio').append("<div class='col-sm-3' id="+id+">"
								+"<audio controls='controls'><source src="+strValue.wlin_voice[i]+" type='audio/mp3' width='320' height='240'></audio>"
								+"<button type='button' class='btn btn-danger' onclick='delaudio(this)' style='display:none'><i class='icon icon-trash bigger-130'></i> 删除</button></div>");
					}
				}
				
				if(strValue.wlin_video.length==0){
					
				}else{
					for(var i=0;i<strValue.wlin_video.length;i++){
						
						var id=strValue.wlin_video[i].split('/')[3];
						$('#showvideo').append("<div class='col-sm-3' id="+id+">"
								+"<video src="+strValue.wlin_video[i]+" type='video/mp4' controls width='320' height='240'>Your browser does not support the video tag.</video>"
								+"<button type='button' class='btn btn-danger' onclick='delvideo(this)' style='display:none'><i class='icon icon-trash bigger-130'></i> 删除</button></div>");
					}
				}

				
			}else if(e.target.hash=='#setting'){
				$('#ZW1').val(strValue.zw1);
				$('#ZW2').val(strValue.zw2);
				$('#ZW3').val(strValue.zw3);
				$('#ZW4').val(strValue.zw4);
				$('#ZW5').val(strValue.zw5);
				$('#ZW6').val(strValue.zw6);
				
				$('#NL1').val(strValue.nl1);
				$('#NL2').val(strValue.nl2);
				$('#NL3').val(strValue.nl3);
				$('#NL4').val(strValue.nl4);
				$('#NL5').val(strValue.nl5);
				$('#NL6').val(strValue.nl6);
				
				$('#HL').val(strValue.hl);
				$('#HP').val(strValue.hp);
				$('#JH').val(strValue.jh);
				$('#RG').val(strValue.rg);
				$('#ZZ').val(strValue.zz);
				
				$('#BR').val(strValue.br);
				$('#ZBR').val(strValue.zbr);
				$('#YL').val(strValue.yl);
				$('#ZYL').val(strValue.zyl);
				$('#LQ').val(strValue.lq);
				$('#ZLQ').val(strValue.zlq);
				$('#NL').val(strValue.nl);
				$('#ZNL').val(strValue.znl);
				$('#ZW').val(strValue.zw);
				$('#ZZW').val(strValue.zzw);
			}
});
